﻿package com.wandian.utils
{
	import flash.text.TextField;
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.text.TextFormat;

	public class Debuger
	{

		public static var monitor:TextField=new TextField();
		private static var displayed:Boolean=false;
		private static var inited:Boolean=false;
		private static var stage:Stage;


		public static function show():void
		{
			displayed=true;
			stage.addChild(monitor);
		}

		public static function hide():void
		{
			displayed=false;
			stage.removeChild(monitor);
		}

		public static function init(swf:Stage):void
		{
			if (inited)
			{
				return;
			}
			;
			inited=true;
			stage=swf;
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			monitor.width=stage.stageWidth;
			monitor.height=stage.stageHeight;
			monitor.background=true;
			monitor.backgroundColor=0x999999;
			var format:TextFormat=new TextFormat();
			format.color=0xFF00;
			format.size=16;
			format.font="Arial";
			monitor.defaultTextFormat=format;
		}

		protected static function onKeyDown(event:KeyboardEvent):void
		{
			if (event.keyCode == 36)
			{
				if (displayed)
				{
					hide();
				}
				else
				{
					show();
				}
				;
			}
			;
		}

		public static function print(str:String):void
		{
			monitor.text=((str + "\r") + monitor.text);
		}

	}
} //package mx.AnSense.util
